<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/vue.js"></script>
</head>

<body>
    <!-- 
        v-for指令
            1、用于展示列表数据
            2、语法：v-for="(item,index) in xxx" :key="index"
            3、可遍历：数组、对象、字符串(用的少)、指定次数(用的少)
     -->
    <div id="app">
        <!-- 遍历数组 (用的最多)-->
        <ul>
            <li v-for="(p,index) in persons" :key="index"> {{p.name}}-{{p.age}} </li>
        </ul>
        <hr />
        <!-- 遍历对象 -->
        <ul>
            <li v-for="(v,k) in myObject" :key="k"> {{k}}:{{v}} </li>
        </ul>
        <!-- 遍历字符串 -->
        <ul>
            <li v-for="(item,index) in str" :key="index"> {{index}}:{{item}} </li>
        </ul>
        <!-- 遍历指定次数 -->
        <ul>
            <li v-for="(item,index) in 5" :key="index"> {{index}}:{{item}} </li>
        </ul>
    </div>
    <script>
        Vue.config.productionTip = false
        const vm = new Vue({
            data() {
                return {
                    persons: [
                        { id: '001', name: 'zsan', age: 18 },
                        { id: '002', name: 'lisa', age: 19 },
                        { id: '003', name: 'lsi', age: 20 }
                    ],
                    myObject: {
                        title: '测试',
                        price: '200',
                        color: '白色'
                    },
                    str: 'hello'
                }
            }
        })
        vm.$mount('#app')
    </script>
</body>

</html>